package org.rency.crawler.fetch.converter;

import java.util.ArrayList;
import java.util.List;
import org.apache.commons.collections.CollectionUtils;
import org.rency.crawler.dal.entity.BaseDO;
import org.rency.crawler.domain.vo.BaseDomain;

/**
 * 描述: ${TODO}<br>
 * 最近修改时间:2017/11/20 18:02<br>
 *
 * @author CaiyuRen
 * @version V1.0
 * @since 2017/11/20 18:02
 */
public abstract class AbstractDomainConvertor<Domain extends BaseDomain, Entity extends BaseDO> implements DomainConvertor<Domain, Entity>{

  @Override
  public List<Domain> convertDomain(List<Entity> entities) {
    if(CollectionUtils.isEmpty(entities)){
      return new ArrayList<Domain>();
    }
    List<Domain> result = new ArrayList<>(entities.size());
    for(Entity entity : entities){
      result.add(this.convertDomain(entity));
    }
    return result;
  }

  @Override
  public List<Entity> convertEntity(List<Domain> domains) {
    if(CollectionUtils.isEmpty(domains)){
      return new ArrayList<Entity>();
    }
    List<Entity> result = new ArrayList<>(domains.size());
    for(Domain entity : domains){
      result.add(this.convertEntity(entity));
    }
    return result;
  }

}
